<?php
/**
 * Goods
 * Created by Veyron
 * motto:现在的拼搏 为了更好的明天
 * day:  2020/2/7
 * Time: 15:55
 */

namespace app\common\model\mysql;

use think\Model;

class BaseModel extends Model
{
    /**
     * 自动写入时间
     * @var bool
     */
    public $autoWriteTimestamp = true;
    public function updateById($id,$data){
        $data['update_time'] = time();
        return $this->where('id',$id)->save($data);
    }

    public function getNormalInIds($ids,$field = true){

        $result = $this->whereIn('id',$ids)
                        ->where('status','=',config('status.mysql.table_normal'))
                        ->field($field)
                        ->select();

        return  $result;
    }

    /**
     * 根据条件查询
     * @param $condition
     * @param array $oredr
     * @return bool|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getByCondition($condition, $oredr = ['id'=>'desc']){
        if(!$condition){
            return false;
        }
        $result = $this->where($condition)
                        ->order($oredr)
                        ->select();
        return $result;
    }
    /**
     * 根据条件查询
     * @param $condition
     * @param array $oredr
     * @return bool|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getInByIds($whereIn, $condition = [],  $order = ['id'=>'desc']){

        $result = $this->whereIn($whereIn[0], $whereIn[1])
            ->where($condition)
            ->order($order)
            ->select();
        return $result;
    }
}

